package com.Web_02;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "RequestDemo1", value = "/RequestDemo1")
public class RequestDemo1 extends HttpServlet {

    /*
    String getMethod()              获取请求方式
    String getCodePath()            获取项目的虚拟路径（项目名
    String getRequestURi()          获取uri  com.Web_02.RequestDemo1
    StringBuffer getRequestUrl()    获取url  http://localhost:8080/com.Web_02.RequestDemo1
    String getProtocol()            获取协议和版本号
    String getRemoteAddr()          获取客户端ip地址
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        String getMethod()              获取请求方式

        String method= request.getMethod();
        System.out.println("请求方式:"+method);
//         String getCodePath()            获取项目的虚拟路径（项目名）
        String contextPath= request.getContextPath();
        System.out.println("虚拟路径:"+contextPath);
//        String getRequestURl()          获取url  com.Web_02.RequestDemo1
        String RequestURl=request.getContextPath();
        System.out.println("uri:"+RequestURl);
//        StringBuffer getRequestUrl()    获取url
        StringBuffer  RequestUrl=request.getRequestURL();
        System.out.println("url:"+RequestUrl);
//         String getProtocol()            获取协议和版本号
        String  Protocol=request.getProtocol();
        System.out.println("协议和版本本号："+Protocol);
//         String getRemoteAddr()          获取客户端ip地址
        String RemoteAddr=request.getRemoteAddr();
        System.out.println("客户端ip："+RemoteAddr);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request,response);
    }
}
